package com.supermarket.seefood51.home.model

import android.content.Context
import com.example.http.HttpManager
import com.example.http.listener.HttpOnNextListener
import com.supermarket.seefood51.api.MainApi
import com.supermarket.seefood51.api.ProductApi
import com.supermarket.seefood51.entity.SeaFoodEntity
import com.supermarket.seefood51.entity.SeaFoodParentEntity
import com.supermarket.seefood51.linstener.OnLoadRequestListener
import com.trello.rxlifecycle.components.support.RxAppCompatActivity

class ProductModel {
    fun requestList(context: Context, worNumber: String, listener: OnLoadRequestListener<List<SeaFoodParentEntity>>) {
        val mainApi = ProductApi(context as RxAppCompatActivity, worNumber, object :
                HttpOnNextListener<List<SeaFoodParentEntity>>() {
            override fun onNext(t: List<SeaFoodParentEntity>?) {
                listener.onSuccess(t!!)
            }

            override fun onError(e: Throwable?) {
                listener.onFail(e)
            }
        })
        //采用已经封装完毕的RX+Retrofit框架
        HttpManager.getInstance().doHttpDeal(mainApi)
    }

    fun addCart(t: SeaFoodEntity) {

    }


}
